package com.lmq.funcPro;

import java.util.function.Function;

/**
 * unbound method ref refers to an ordinary non-static method
 * without an associate obj.To apply an unbound ref, you must supply the
 * obj:
 */

class X {
    String f() { return "X::f()"; }
}

interface MakeString {
    String make();
}

interface TransformX {
    String transform(X x);
}


public class UnboundMethodReference {
    public static void main(String[] args) {
        // MakeString ms = X::f;
        TransformX sp = X::f;
        X x = new X();
        System.out.println(sp.transform(x));
        System.out.println(x.f()); // same effect
    }
}
/**
 * so far weve seen ref to methods that have the same signture as their
 * associated interface. At[1] , we try to do the same thing for f()
 * in X, attempting t assing to a makeString. This produces an error form the compiler about
 * an invalid method reference, even though make() has the smae sigature as
 * f(). The problem is that there is actually another argument involved: our old friend this.
 * You can't call f() without an X object to call it upon. Thus, X::f represents an unbound method reference,
 * because it hasn't been bound to an object.
 * We need X object, so interface actually need an extra argument, as you see in TransformX.If you
 * assign X::f to a TransformX，java is happy. We must now make a second
 * mental adjustment - with an unbound reference, the signature of the functional method (the single method in the
 * interface) no longer quit matches the signature of the method reference.
 * There is a good reason, which is that you
 * need an object to call the method on.
 */